/*
 * @(#)PACKAGE_NAME 2020/3/7/0007
 *
 * Copy Right@ 人人译视界
 */


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <pre>
 * @author tuwei
 *
 * @version 0.9
 *
 * 修改版本: 0.9
 * 修改日期: 2020/3/7/0007
 * 修改人 :  tuwei
 * 修改说明: 初步完成
 * 复审人 ：
 * </pre>
 */
public class BIORpcProxyServer {
	/**
	 * 发布服务
	 * @param service
	 * @param port
	 */
	public void publisher(Object service, int port) throws IOException {
		ExecutorService es = Executors.newFixedThreadPool(10);
		// BIO(阻塞IO)
		ServerSocket serverSocket = null;

		InputStream is = null;
		OutputStream os = null;
		try {
			// 服务端吞吐量很低
			serverSocket = new ServerSocket(port);
			while(true) {
				Socket socket = serverSocket.accept();
				es.execute(new BIOProcessHandlerThread(service, socket));
			}
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			if (is != null) {
				is.close();
			}
			if (os != null) {
				os.close();
			}
		}
	}
}
